; ntload : POSNT Loader ,Version 0.2.3
; Loads Kernels!
; We are loaded by boot.bin at 0x1000:0x0000
jmp stage_2_main ; 0x0000 Called From Bootloader
jmp FONT ; 0x0003 ---> For the Kernel
stage_2_main:
	cli				; Clear interrupts
	mov ax, 0
	mov ss, ax			; Set stack segment and pointer
	mov sp, 0FFFFh
	sti				; Restore interrupts

	cld				; The default direction for string operations
					; will be 'up' - incrementing address in RAM

	mov ax, 1000h			; Set all segments to match where kernel is loaded
	mov ds, ax			; After this, we don't need to bother with
	mov es, ax			; segments ever again, as MikeOS and its programs
	mov fs, ax			; live entirely in 64K
	mov gs, ax
stage_2_boot_menu:		
.cls:
	call os_clear_screen
	
	mov bl, 0x02	; White on red
	mov dl, 20		; Start X position
	mov dh, 12		; Start Y position
	mov si, 48		; Width
	mov di, 13		; Finish Y position
	call os_draw_block
	mov dl,20
	mov dh,12
	call os_move_cursor
	mov si,init
	call os_print_string
	mov dl,0
	mov dh,23
	call os_move_cursor
	mov si,ver
	call os_print_string
	mov dl,0
	mov dh,20
	call os_move_cursor
	mov si,loading
	call os_print_string
	mov bl, 0x8F	; White on red
	mov dl, 0		; Start X position
	mov dh, 21		; Start Y position
	mov si, 80		; Width
	mov di, 22		; Finish Y position
	call os_draw_block
	mov bl, 0xFF	; White on red
	mov dl, 0		; Start X position
	mov dh, 21		; Start Y position
	mov si, 10		; Width
	mov di, 22	; Finish Y position
	call os_draw_block
	mov ax,2
	call os_pause
	mov bl, 0xFF	; White on red
	mov dl, 10		; Start X position
	mov dh, 21	; Start Y position
	mov si, 15		; Width
	mov di, 22		; Finish Y position
	call os_draw_block
	mov ax,6
	call os_pause
	mov bl, 0xFF	; White on red
	mov dl, 25		; Start X position
	mov dh, 21		; Start Y position
	mov si, 30		; Width
	mov di, 22; Finish Y position
	call os_draw_block
	mov ax,7
	call os_pause
	mov bl, 0xFF	; White on red
	mov dl, 55		; Start X position
	mov dh, 21		; Start Y position
	mov si, 10		; Width
	mov di, 22	; Finish Y position
	call os_draw_block
	mov ax,2
	call os_pause
	mov bl, 0xFF	; White on red
	mov dl, 55		; Start X position
	mov dh, 21		; Start Y position
	mov si, 15		; Width
	mov di, 22	; Finish Y position
	call os_draw_block
	mov ax,4
	call os_pause
	jmp .stuff_done
.stuff_done:
	mov ax, .title_msg
	mov bx, .footer_msg
	mov cx, 0x9F	; Colour
	call os_draw_background
	
.draw_lst:
	mov ax, .list
	mov bx, .msg1
	mov cx, .msg2
	call os_list_dialog
	jc .esc_pressed

	; Now AX = number (from 1) of option chosen
	cmp ax,1
	je boot_kern_f
	cmp ax,2
	je .draw_lst
	cmp ax,3
	je load_kernel3
	cmp ax,4
	je detect_hardware
	cmp ax,5
	je ACPI_SHUTDOWN
	cmp ax,6
	je reboot
.esc_pressed:
	jmp reboot

	.list	db 'POSNT 1.1.7.2,Start the Debugger,User Kernel (USERKRNL.EXE),Detect Hardware,Shutdown,Reboot', 0
	.msg1	db 'POSx86 BootManager', 0
	.msg2	db 'Choose a Boot Option', 0
	.title_msg	db '                                 POS Boot Manager      ', 0
	.footer_msg	db 'Version 0.2.3 2013', 0                                
reboot:
	mov al,0xFE
	out 0x64,al
boot_kern_f:
	jmp boot_kern
other_kern:
	jmp otr_kern
clear:
	call os_clear_screen
	jmp os_return
load_krn2:
	jmp load_kernel3
.data:
	loading db 'POS is Loading Files.......                                 Please Wait..',0
	ver db '(C) Alldesplay Corporation 2013',0
	init db '          NTLOAD Boot Options',0
	wait_msg db 'Press Esc to goto the Boot Manager (or Wait for a while)',0
%include "VGA/io.asm"
%include "VGA/wait_key.asm"
%include "LOAD/loadkrn.asm"
%include "LOAD/DET.ASM"
%include "VGA/otr_kern.asm"
%include "LOAD/ext_kern.asm"
%include "HARDWARE/hardware.asm"
%include "HARDWARE/kern_info.asm"
%include "VGA/pause.asm"
%include "DRIVER/drv16.asm"
%include "LOAD/usrkrn.asm"
%include "VGA/FONT.FNT"